package javasql;

import java.sql.*;
import java.util.Scanner;

public class Jdbc8 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        String url = "jdbc:mysql://localhost:3306/kgb762?useSSL=false";
        Connection con = null;
        PreparedStatement  st = null;
        try {
            con = DriverManager.getConnection(url, "root", "123456");
            System.out.println(con.getClass().getName());
            Scanner input=new Scanner(System.in);
            System.out.println("请输入删除的id：");
            int id=input.nextInt();
            String sql="DELETE FROM s_student WHERE stuno=?;";
            System.out.println(sql);
            st = con.prepareStatement(sql);
            st.setInt(1,id);
            int num = st.executeUpdate();
            System.out.println("%d行被删除了"+num);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                st.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
